//
//  HTKiPhoneXUtil.m
//  HTKDynamicTemplate
//
//  Created by minor on 2017/11/10.
//

#import "HTKiPhoneXUtil.h"
#import <sys/types.h>
#import <sys/sysctl.h>
#import <net/if.h>
#import <net/if_dl.h>

@implementation HTKiPhoneXUtil

+ (CGFloat)htl_statusBarHeightIncresmentIfiPhoneX
{
    if ([self htk_isiPhoneX]) {
        return 24.f;
    } else {
        return 0.f;
    }
}

+ (BOOL)htk_isiPhoneX
{
#if DEBUG
    CGRect frame = [UIScreen mainScreen].bounds;
    return frame.size.height == 812;
#else
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);
    
    if ([platform isEqualToString:@"iPhone10,3"] ||
        [platform isEqualToString:@"iPhone10,6"]) {
        return YES;
    }
    return NO;
#endif
}

@end
